import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);
import vuexPersist from "vuex-persist";
export default new Vuex.Store({
  state: {
    list: [],
    active: 0,
  },
  mutations: {
    setlist(state, val) {
      state.list = val;
    },
    setactive(state, val) {
      state.active = val;
    },
    remove(state, sel) {
      // sel 要删除的数据的id集合
      state.list = state.list.filter((item) => {
        return sel.includes(item.id) == false;
      });
      //把要留的留下来
    },
    //选中删除效果

    // change1(state, index) {
    //   state.list[index].state = 2;
    // },
    // change2(state, index) {
    //   state.list[index].state = 3;
    // },
    // change3(state, index) {
    //   state.list[index].state = 4;
    // },
    // change4(state, index) {
    //   state.list[index].state = 1;
    // },
    change(state, index) {
      if (state.active == 4) {
        state.list[index].state = 1;
      } else {
        state.list[index].state++;
      }
    },
  },
  actions: {},
  modules: {},
  plugins: [
    new vuexPersist({
      localstorage: window.localStorage,
    }).plugin,
  ],
});
